package com.tx.activemq;

import lombok.Data;
import org.springframework.jms.core.MessageCreator;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

@Data
public class DefaultMessageCreator implements MessageCreator {

    private DefaultMessage message;

    @Override
    public Message createMessage(Session session) throws JMSException {
        return session.createObjectMessage(this.message);
    }

    public static DefaultMessageCreator getInstance(DefaultMessage message) {
        DefaultMessageCreator defaultMessageCreator = new DefaultMessageCreator();
        defaultMessageCreator.setMessage(message);
        return defaultMessageCreator;
    }
}
